﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.SessionState;

namespace HRProject.Code.Common
{
    public class Util
    {
        public static string GetSessionID(HttpSessionState session)
        {
            string id = (string)session["BLSessionID"];
            if (id == null)
            {
                id = session.SessionID;
                session["BLSessionID"] = id;
            }
            return id;
        }

        public static void CloseFrame(HttpResponse response)
        {
            string script = "<script language=\"javascript\">";
            script += "window.parent.refresh();";
            script += "</script>";
            response.Write(script);
        }

        public static void CloseDialog(HttpResponse response)
        {
            string script = "<script language=\"javascript\">";
            
            script += "window.close();";
            script += "window.opener.refresh();";
            script += "</script>";
            response.Write(script);
        }

        public static void CloseDialogWithoutRefresh(HttpResponse response)
        {
            string script = "<script language=\"javascript\">";
            script += "window.close();";
            script += "</script>";
            response.Write(script);
        }

        public static void Refresh(HttpResponse response)
        {
            string script = "<script language=\"javascript\">";
            script += "refresh();";
            script += "</script>";
            response.Write(script);
        }

        public static void Alert(HttpResponse response, string message)
        {
            string script = "<script language=\"javascript\">";
            script += "alert(\""+message+"\");";
            script += "</script>";
            response.Write(script);
        }

        public static string CustomFormat(string s)
        {
            if (s == null)
                return string.Empty;
            string temp = s.Replace('.', '|');
            temp = temp.Replace(',', '.');
            temp = temp.Replace('|', ',');
            return temp;
        }
    }
}
